package com.itheima.oopadvanced.util;

/**
 * @author Anomaly
 * @date 2022/12/9 11:33
 */

import java.util.Random;

/**
 * 工具类
 */
public class CodeUtil {
    private CodeUtil() {
    }

    /**
     * 生成n位验证码
     *
     * @param n 验证码长度
     * @return
     */
    public static String createCode(int n) {
        String code = "";
        String data = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            code += data.charAt(random.nextInt(data.length()));
        }
        return code;
    }
}
